<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-card class="box-card">
          <template v-slot:header>
            <div class="clearfix">
              <span>个人信息</span>
            </div>
          </template>
          <div>
            <div class="text-center">
              <user-avatar :user="state.user" />
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <el-icon><Avatar /></el-icon><b class="m-l">用户名称</b>
                <div class="pull-right">{{ state.user.username }}</div>
              </li>
              <li class="list-group-item">
                <el-icon><Iphone /></el-icon><b class="m-l">手机号码</b>
                <div class="pull-right">{{ state.user.phoneNumber }}</div>
              </li>
              <li class="list-group-item">
                <el-icon><ChatLineSquare /></el-icon><b class="m-l">用户邮箱</b>
                <div class="pull-right">{{ state.user.email }}</div>
              </li>
              <li class="list-group-item">
                <el-icon><UserFilled /></el-icon><b class="m-l">所属角色</b>
                <div class="pull-right">{{ state.roleName }}</div>
              </li>
              <li class="list-group-item">
                <el-icon><TrendCharts /></el-icon><b class="m-l">创建日期</b>
                <div class="pull-right">
                  {{ parseTime(state.user.createTime) }}
                </div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18" :xs="24">
        <el-card>
          <template v-slot:header>
            <div class="clearfix">
              <span>基本资料</span>
            </div>
          </template>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本资料" name="userinfo">
              <user-info :user="state.user" />
            </el-tab-pane>
            <el-tab-pane label="修改密码" name="resetPwd">
              <reset-pwd :user="state.user" />
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup name="Profile">
import { reactive, ref } from "vue";
import * as userApi from "@/api/system/userApi";
import UserAvatar from "./UserAvatar";
import UserInfo from "./UserInfo";
import ResetPwd from "./ResetPwd";

const activeTab = ref("userinfo");

const state = reactive({
  user: {},
  roleName: {},
});

function getUser() {
  userApi.getUserProfile().then((res) => {
    state.user = res.data.userDTO;
    console.log(res.data.userDTO);
    state.roleName = res.data.roleDTO.roleName;
  });
}

getUser();
</script>

<style lang="scss" scoped>
.list-group-striped > .list-group-item {
  border-left: 0;
  border-right: 0;
  border-radius: 0;
  padding-left: 0;
  padding-right: 0;
}

.list-group {
  padding-left: 0px;
  list-style: none;
}

.list-group-item {
  border-bottom: 1px solid #e7eaec;
  border-top: 1px solid #e7eaec;
  margin-bottom: -1px;
  padding: 11px 0px;
  font-size: 13px;
}

.pull-right {
  float: right;
}

.m-l {
  margin-left: 5px;
}
</style>
